python search for string in file

37

python search for string in file -

with open('example.txt') as f:
    if 'blabla' in f.read():
        print("true")

python : search file for string -

import mmap

with open('example.txt') as f:
    s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    if s.find('blabla') != -1:
        print('true')

Comments

Submit
0 Comments